/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: QuartzConfig
 * Author:   pc
 * Date:     2019/8/30 11:00
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.example.rabbitmqdemo.config;

import com.example.rabbitmqdemo.entity.JobEntity;
import com.example.rabbitmqdemo.task.QuartzTestTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author pc
 * @create 2019/8/30
 * @since 1.0.0
 */
@Configuration
public class QuartzConfig {
	@Bean
	public JobDetail quatzTestTaskDetail() {
		return JobBuilder.newJob(QuartzTestTask.class).withIdentity("quartzTest").storeDurably().build();
	}

	//
//	@Bean
//	public Trigger uploadTaskTrigger() {
//		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("*/5 * * * * ?");
//		return TriggerBuilder.newTrigger().forJob(uploadTaskDetail())
//				.withIdentity("uploadTask")
//				.withSchedule(scheduleBuilder)
//				.build();
//	}
	//获取Trigger (Job的触发器,执行规则)
	public Trigger getTrigger(JobEntity job) {
		return TriggerBuilder.newTrigger()
				.withIdentity(job.getName(), job.getGroup())
				.withSchedule(CronScheduleBuilder.cronSchedule(job.getCron()))
				.build();
	}

}